package com.zhouyu.exampleSpSource.controller;

import com.zhouyu.commonapi.resbody.ResBody;
import com.zhouyu.commonapi.utils.JsonUtil;
import com.zhouyu.commonapi.utils.algorithm.AesAlgorithmUtil;
import com.zhouyu.commonapi.utils.algorithm.Decrypt;
import com.zhouyu.commonapi.utils.algorithm.Encrypt;
import com.zhouyu.exampleSpSource.param.LerongParam;
import com.zhouyu.exampleSpSource.vo.LerongVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * Description: 加解密
 *
 * @author zhouyu
 * @create 2020/9/7
 * @since 1.0.0
 */
@RestController
@RequestMapping("/aes")
public class DesController {
    private Logger logger = LoggerFactory.getLogger(DesController.class);

    @PostMapping("/no")
    public ResBody testNoAes(@RequestBody @Valid LerongParam lerongParam){
        logger.info("请求参数：{}",lerongParam);
        LerongParam param = new LerongParam();
        param.setId("12242343lkl88998");
        param.setName("zhouyu");
        String json = JsonUtil.object2Json(param);
        String aesStr = "";
        try {
            aesStr = AesAlgorithmUtil.aesEncrypt(json, "d86d7bab3d6ac01ad9dc6a897652f2d2");
            String decryStr = AesAlgorithmUtil.aesDecrypt(aesStr, "d86d7bab3d6ac01ad9dc6a897652f2d2");
            logger.info(decryStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        logger.info("加密:{}",aesStr);
        return ResBody.SUCCESS(aesStr);
    }


    @Encrypt
    @Decrypt
    @PostMapping("/yes")
    public ResBody testAes(@RequestBody @Valid LerongParam lerongParam){
        logger.info("解密后的参数：{}",lerongParam);
        LerongVo lerongVo = new LerongVo();
        lerongVo.setFee("2000");
        lerongVo.setOrderId("223423h42342342");
        return ResBody.SUCCESS(lerongVo);
    }
}
